<template>
    	<el-form ref="elForm" :model="fmodel" status-icon :rules="rules" label-width="1.5rem">
            <el-form-item label="归档原因:" prop="modReason" required>
				<el-input type="textarea" v-model="fmodel.modReason" :rows="2" placeholder="请输入内容"></el-input>
			</el-form-item>

            <el-form-item>
				<el-button type="primary" @click="validate">确定</el-button>
				<el-button @click="close">取消</el-button>
			</el-form-item>
        </el-form>


</template>
<script>
import { mapState } from "vuex";
import CustOrderService from "@/api/order/CustOrderService";
export default {
  computed: {
    ...mapState("user", ["user"]),
  },
   name: "reqActivationOrder",
   data() {
       return {
           newCTOInfo:[],
           orderItemIds:"",
           orderItemSeqs:"",
           fmodel:{
               modReason:"",
           },
           rules:{
               modReason: [
                 {required: true, message: '归档原因不能为空', trigger: 'blur'},
                ],
           }
       }
   },
   props: {
      ODKInfo: {
        type: Object,
        default: () => {
          return {};
        },
      },
      CTOInfo: {
        type: [Object, Array],
        default: () => {
          return {};
        },
      },
    },
   mounted(){
         
    if(this.CTOInfo instanceof Array){
      this.newCTOInfo = this.CTOInfo;
    }else{
      this.newCTOInfo = [this.CTOInfo];
    }
    
    if(this.newCTOInfo.length > 0){
      var orderItemIds="";
      var orderItemSeqs="";
      for(var i=0;i<this.newCTOInfo.length;i++){
         if(i==0){
           orderItemIds += this.newCTOInfo[i].orderItemId;
           orderItemSeqs += this.newCTOInfo[i].orderItemSeq;
         }else{
            orderItemIds += ","+this.newCTOInfo[i].orderItemId;
            orderItemSeqs += ","+this.newCTOInfo[i].orderItemSeq;
         }
      }
      this.orderItemIds = orderItemIds;
      this.orderItemSeqs = orderItemSeqs;
    }
   },
   methods:{
        validate() {
            this.$refs['elForm'].validate((valid) => {
                
                if (valid) {
                // 成功
                this.confirm();
                } else {
                
                return false;
                }
            });
        },
        async confirm(){
             var custOrder = JSON.parse(localStorage.getItem("custOrder_select"));
             var param = {
                 custSoNumber:custOrder.custSoNumber,
                 custId:custOrder.custId,
                 orderItemSeq:this.orderItemSeqs,
                 modReason:this.fmodel.modReason,
                 staffId:this.user.staffId,
                 orgId:this.user.orgId
             }
             

             var result= await CustOrderService.reqOrderAchive(param);
             

             if(result.meta.resultCode == '1'){
                  this.$message.warning(result.meta.resultMsg);
             }else if(result.meta.resultCode == '0'){
                  this.$message.success("需求单归档成功");
             }
        },
        close(){
             this.$emit("close");
        }
   }
}
</script>

<style scoped>

</style>
